import 'package:flutter/material.dart';
import 'package:full_display/unit/screen/screen_utility.dart';
import 'package:full_display/unit/widgets/custom_progress/custom_linear_progress.dart';

class LinearProgressWidget extends StatefulWidget {

  final Function callBack;
  final Function endCallBack;

  const LinearProgressWidget({Key? key, required this.callBack, required this.endCallBack}) : super(key: key);

  @override
  State<LinearProgressWidget> createState() => _LinearProgressWidgetState();
}

class _LinearProgressWidgetState extends State<LinearProgressWidget> {

  var left = 20.0;

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onHorizontalDragEnd: (detail){
        var screen = MediaQuery.of(context).size.width-178;
        var anum = ((left/screen)*100).toStringAsFixed(0);
        widget.endCallBack.call(double.parse(anum));
      },
      onHorizontalDragUpdate: (details) {
        setState(() {
          var temp = details.localPosition.dx;
          var screen = MediaQuery.of(context).size.width-178;
          if (temp > screen ) {
            temp = screen ;
          } else if (temp < 0) {
            temp = 0;
          }else{
          }
          left = temp;
          var anum = ((left/screen)*100).toStringAsFixed(0);
          widget.callBack.call(double.parse(anum));
        });
      },
      child: Container(
        color: Colors.transparent,
        height: 56.0.H,
        margin: EdgeInsets.only(left: 12.0.W,right: 12.0.W),
        padding: EdgeInsets.only(top: 26.0.H,bottom: 26.0.H),
        width: MediaQuery.of(context).size.width - 178,
        child: CustomPaint(
          painter: CustomLinearProgress(
              width: MediaQuery.of(context).size.width - 178,
              widthTop: left ),
        ),
      ),
    );
  }
}
